package com.smartEdu.controller.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.smartEdu.commons.LogCvt;
import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.exception.RequestException;
import com.smartEdu.exception.ServiceException;
import com.smartEdu.response.Response;
import com.smartEdu.service.ExamService;
import com.smartEdu.service.HomeWorkService;
import com.smartEdu.service.RongCloudeService;
import com.smartEdu.service.StatisticalService;

@Controller
@RequestMapping(value="app")
public class HomeworkController extends AppBaseController{
	public static final String TAG="HomeworkController";
	@Autowired
	@Qualifier(value="appresponse")
	public Response respContext;
	
	@Autowired
	@Qualifier(value="homeWorkServiceImpl")
	public HomeWorkService homeWorkService;
	
	@Autowired
	@Qualifier(value="rongCloudeServiceImpl")
	public RongCloudeService rongCloudeService;
	
	@RequestMapping(value="home")
	public void HomePage(HttpServletRequest request,HttpServletResponse response){
		SetResponse(response, GetSession());
	}

	@Override
	public String GetRespContent(Session sess) {
		return respContext.GetRespContent(sess);
	}
	
	@RequestMapping(value="/homepage/homework")
	public void HomeWork(HttpServletRequest request,HttpServletResponse response){
//		Session session=new Session();
//		session.put(Tag_Tips.RESPCODE, Tag_Tips.OK);
//		List<Map<String, Object>> list=new ArrayList<>();
//		Map<String, Object> map1=new HashMap<>();
//		Map<String, Object> map2=new HashMap<>();
//		map1.put("pk", "abcdef123sdase");
//		map1.put("icon", "http://115.28.164.193/smed/course/1.jpg");
//		map1.put("cname", "java编程之美");
//		map1.put("hname", "第五章-反射机制");
//		map1.put("htype", 1);
//		map1.put("quessnum", 8);
//		map1.put("personsum", 50);
//		map1.put("dosum", 16);
//		map1.put("endtime", 1472108400);
//		map2.put("pk", "abcdef123sdasf");
//		map2.put("icon", "http://115.28.164.193/smed/course/2.jpg");
//		map2.put("cname", "C语言基础");
//		map2.put("hname", "第二章-指针的陷阱");
//		map2.put("htype", 1);
//		map2.put("quessnum", 10);
//		map2.put("personsum", 50);
//		map2.put("dosum", 26);
//		map2.put("endtime", 1472119400);
//		list.add(map1);
//		list.add(map2);
//		session.put("hms", list);
//		SetResponse(response, session);
//		Session sess=null;
//		try {
//			sess=GetSession();
//			sess.put(Tag_Tips.REQUEST, GetParameter(request));
//			
//			
//		} catch (RequestException e) {
//			LogCvt.error(TAG+" - "+"获取课程作业提醒异常,请求参数为空");
//		}
//		catch (Exception e) {
//			LogCvt.error("获取request异常");
//		}
//		SetResponse(response, GetSession());
//		Session session=new Session();
//		session.put(Tag_Tips.RESPCODE, Tag_Tips.OK);
//		List<Map<String, Object>> list=new ArrayList<>();
//		Map<String, Object> map1=new HashMap<>();
//		Map<String, Object> map2=new HashMap<>();
//		map1.put("pk", "abcdef123sdase");
//		map1.put("icon", "http://115.28.164.193/smed/course/1.jpg");
//		map1.put("cname", "java编程之美");
//		map1.put("hname", "第五章-反射机制");
//		map1.put("htype", 1);
//		map1.put("quessnum", 8);
//		map1.put("personsum", 50);
//		map1.put("dosum", 16);
//		map1.put("endtime", 1472108400);
//		map2.put("pk", "abcdef123sdasf");
//		map2.put("icon", "http://115.28.164.193/smed/course/2.jpg");
//		map2.put("cname", "C语言基础");
//		map2.put("hname", "第二章-指针的陷阱");
//		map2.put("htype", 1);
//		map2.put("quessnum", 10);
//		map2.put("personsum", 50);
//		map2.put("dosum", 26);
//		map2.put("endtime", 1472119400);
//		list.add(map1);
//		list.add(map2);
//		session.put("hms", list);
//		SetResponse(response, session);
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			homeWorkService.homeWork2(sess);
			
		} catch (RequestException e) {
			LogCvt.error(TAG+" - "+"获取课程作业提醒异常,请求参数为空");
		}
		catch (Exception e) {
			LogCvt.error("获取request异常");
		}
		SetResponse(response, sess);
	}
	
	@RequestMapping(value="/homework/detail")
	public void homeWorkDetail(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			homeWorkService.homeWorkDetail(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}
	
	@RequestMapping(value="/rongcloude/getToken")
	public void getRongColudeToken(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			rongCloudeService.getRongCloudeToken(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}
	
	
	@RequestMapping(value="homework/exam/submitHomework")
	public void homeworkSubmit(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try{
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST,GetParameter(request));
			homeWorkService.homeworkSubmit(sess);
		}catch(ServiceException e){
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}finally {
			SetResponse(response, sess);
		}
	}
}
